package com.lantosec.hmrp.modules.internal.controller.app;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.core.mvc.BaseController;
import com.lantosec.hmrp.modules.internal.service.IInternalTaskService;
import com.lantosec.hmrp.modules.internal.vo.InternalTaskDetailVO;
import com.lantosec.hmrp.modules.internal.vo.InternalTaskVO;
import com.lantosec.hmrp.modules.internal.vo.InternalTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 *
 * 评价任务 控制器
 *
 * @author AutoCode
 * @since 2020-04-23
 */
@Api(value = "评价任务控制器APP端", tags = "评价任务控制器APP端")
@RestController
@RequestMapping("/internal/app/task")
@Log4j2
public class InternalTaskAppController extends BaseController {
    @Autowired
    private IInternalTaskService service;

    @GetMapping("all")
    @ApiOperation(value = "查询全部")
    public Result<List<InternalTaskVO>> all(){
        return Result.ok(entity2VO(service.list()));
    }

    @GetMapping("getNotFinishAll")
    @ApiOperation(value = "未完成任务列表(当前用户不是评价方)")
    public Result<Page<InternalTaskVO>> getNotFinishAll(@ApiParam(value = "分页对象", required = true) PageVO<InternalTaskVO> page,
                                                        @ApiParam(value = "任务类型") @RequestParam(name = "internalPlanType",required = false) Integer internalPlanType,
                                                        @ApiParam(value = "任务标题") @RequestParam(name = "taskTitle",required = false) String taskTitle,
                                                        @ApiParam(value = "任务开始时间") @RequestParam(name = "startDate",required = false) String startDate,
                                                        @ApiParam(value = "任务结束时间") @RequestParam(name = "endDate",required = false) String endDate,
                                                        @ApiParam(value = "任务状态") @RequestParam(name = "state",required = false) Integer state){
        service.getNotFinishAll(page,internalPlanType,taskTitle,startDate,endDate,state);
        return Result.ok(page);
    }

    @GetMapping("getFinishAll")
    @ApiOperation(value = "已完成任务列表(当前用户不是评价方)")
    public Result<Page<InternalTaskVO>> getFinishAll(@ApiParam(value = "分页对象", required = true) PageVO<InternalTaskVO> page,
                                                     @ApiParam(value = "任务类型") @RequestParam(name = "internalPlanType",required = false) Integer internalPlanType,
                                                     @ApiParam(value = "任务标题") @RequestParam(name = "taskTitle",required = false) String taskTitle,
                                                     @ApiParam(value = "任务开始时间") @RequestParam(name = "startDate",required = false) String startDate,
                                                     @ApiParam(value = "任务结束时间") @RequestParam(name = "endDate",required = false) String endDate,
                                                     @ApiParam(value = "任务状态") @RequestParam(name = "state",required = false) Integer state){
        service.getFinishAll(page,internalPlanType,taskTitle,startDate,endDate,state);
        return Result.ok(page);
    }

    @GetMapping("getNotFinish")
    @ApiOperation(value = "未完成任务列表")
    public Result<Page<InternalTaskVO>> getNotFinish(@ApiParam(value = "分页对象", required = true) PageVO<InternalTaskVO> page,
         @ApiParam(value = "任务类型") @RequestParam(name = "internalPlanType",required = false) Integer internalPlanType,
         @ApiParam(value = "任务标题") @RequestParam(name = "taskTitle",required = false) String taskTitle,
         @ApiParam(value = "任务开始时间") @RequestParam(name = "startDate",required = false) String startDate,
         @ApiParam(value = "任务结束时间") @RequestParam(name = "endDate",required = false) String endDate,
         @ApiParam(value = "任务状态") @RequestParam(name = "state",required = false) Integer state,
         @ApiParam(name ="权限分类，1个人2科室3全员" ,value = "permissionsType") @RequestParam(name = "permissionsType",required = false) Integer permissionsType){
        service.getNotFinish(page,internalPlanType,taskTitle,startDate,endDate,state,permissionsType);
        return Result.ok(page);
    }

    @GetMapping("getFinish")
    @ApiOperation(value = "已完成任务列表")
    public Result<Page<InternalTaskVO>> getFinish(@ApiParam(value = "分页对象", required = true) PageVO<InternalTaskVO> page,
          @ApiParam(value = "任务类型") @RequestParam(name = "internalPlanType",required = false) Integer internalPlanType,
          @ApiParam(value = "任务标题") @RequestParam(name = "taskTitle",required = false) String taskTitle,
          @ApiParam(value = "任务开始时间") @RequestParam(name = "startDate",required = false) String startDate,
          @ApiParam(value = "任务结束时间") @RequestParam(name = "endDate",required = false) String endDate,
          @ApiParam(value = "任务状态") @RequestParam(name = "state",required = false) Integer state,
          @ApiParam(name ="权限分类，1个人2科室3全员" ,value = "permissionsType") @RequestParam(name = "permissionsType",required = false) Integer permissionsType){
        service.getFinish(page,internalPlanType,taskTitle,startDate,endDate,state,permissionsType);
        return Result.ok(page);
    }

    @GetMapping("get")
    @ApiOperation(value = "获取被考评方列表")
    public Result<List<InternalTaskDetailVO> > getParam(@ApiParam(value = "任务id", required = true) @RequestParam(name="internalTaskId") Integer internalTaskId){
        List<InternalTaskDetailVO> internalTaskDetailVOList = service.getParam(internalTaskId);
        return Result.ok(internalTaskDetailVOList);
    }

    @GetMapping("getInternalTaskDetailVO")
    @ApiOperation(value = "获取被考评方的考评项目")
    public Result<List<InternalTypeVO>> getInternalTaskDetailVO(@ApiParam(value = "任务id", required = true) @RequestParam(name="internalTaskId") Integer internalTaskId,
                                                                @ApiParam(value = "方案id", required = true) @RequestParam(name="internalPlanId") Integer internalPlanId,
                                                                @ApiParam(value = "评价方式", required = true) @RequestParam(name="targetMode") Integer targetMode,
                                                                @ApiParam(value = "被考评对象id", required = true) @RequestParam(name="targetId") String targetId){
        List<InternalTypeVO> internalTaskDetailVOList = service.getInternalTaskDetailVO(internalTaskId,internalPlanId,targetMode,targetId);
        return Result.ok(internalTaskDetailVOList);
    }


    @GetMapping("startInternal")
    @ApiOperation(value = "开始考评")
    public Result<List<InternalTypeVO>> startInternal(@ApiParam(value = "方案id", required = true) @RequestParam(name="internalPlanId") Integer internalPlanId){
        List<InternalTypeVO> internalTypeVOList = service.startInternal(internalPlanId);
        return Result.ok(internalTypeVOList);
    }


    @DeleteMapping(value = "delete/{ids}")
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
